package yun.service;

import java.util.List;

/**
 * Iterator Pattern
 */
public abstract class Playlist<E> {
	private int index;
	private List<E> list;

	Playlist(int index, List<E> list) {
		if (!hasItem(index, list)) {
			throw new IllegalArgumentException(String.format("index:%s, list:%", index, list));
		}
		setIndex(index);
		setList(list);
	}

	int getIndex() {
		return index;
	}

	void setIndex(int index) {
		this.index = index;
	}

	List<E> getList() {
		return list;
	}

	void setList(List<E> list) {
		this.list = list;
	}

	int size() {
		return list.size();
	}

	boolean hasItem(int index) {
		return hasItem(index, getList());
	}

	boolean hasItem(int index, List<E> list) {
		if (list == null || list.size() == 0) {
			return false;
		}
		if (index < 0 || index > list.size() - 1) {
			return false;
		}
		return true;
	}

	public abstract boolean hasNext();

	public abstract boolean hasPrevious();

	public abstract E next();

	public abstract E current();

	public abstract E prev();

}
